define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	
	console.info(params);
	$scope.form.father_id=params.father_id;
	$scope.form.fk_unit=params.fk_unit;
	$scope.form.status="0";
	if(params.father_id!='undefined'){
		httpService.post(app.urls.menu_select,{"id":params.father_id},function(data){
			if("0000" === data.code){
				$scope.menu_name = data.data[0].name;
				$scope.findButton(data.data[0].id);
			}else{
				alert(data.msg);
			}
		});
	}else {
		$scope.form.sheet=params.sheet;
		$scope.form.field=params.field;
		$scope.form.type=params.type;
	}
	$scope.findButton=function(menu_id){
		httpService.post(app.urls.button_select,{"menu_id":menu_id},function(data){
			if("0000" === data.code){
				$scope.buttons = data.data;
			}else{
				alert(data.msg);
			}
		});
	}
	
	//查询主管单位和学校
	httpService.post(app.urls.unit_selectUnit,{},function(data){
		if("0000" === data.code){
			$scope.units = data.data;
		}else{
			alert(data.msg);
		}
	});
	
	//查询专家
	$scope.find = function(){
		$scope.form.list='list';
		httpService.postpage(app.urls.expert_select,$scope.form,function(data){
			if("0000" === data.code){
    			$scope.rows = data.data;
    		}else{
    			alert(data.msg);
    		}
		});
	}
	httpService.post(app.urls.role_selectType,{},function(data){
		if("0000" === data.code){
			$scope.form.userrole = data.data[0].type;
			$scope.find();
		}else{
			alert(data.msg);
		}
	});
	//按钮点击事件-条件查询
	$scope.select = function(){
    	$scope.page.current = 1;
    	$scope.find();
    }
	$scope.clickBtn=function(event){
		var menu = {};
		if(event=='add'){
			menu.url = "modules/content/usermanagement/expertCenter/add?fk_menuid="+params.fk_menuid+ "&father_id=" + params.father_id;
			if(params.father_id!='undefined'){
				eventBusService.publish("modules.content.load",menu);
			}else {
				eventBusService.publish("modules.content.load",menu);
			}
		}
		if(event=='update'){
			var values = [];
			$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
				values.push($(this).val());
			});
			if(values.length < 1){
				eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择修改数据。"});
			}else if(values.length > 1){
				eventBusService.publish('modal.alert', {"title":"操作提示","content":"您选择了多行数据，请重新选择。"});
			}else {
				menu.url = "modules/content/usermanagement/expertCenter/update?FatherControllerName=" + $scope.controllerName + "&id=" + values[0] + "&father_id=" + params.father_id+ "&sheet=" + params.sheet+ "&field=" + params.field+ "&type=" + params.type;
				if(params.father_id!='undefined'){
					eventBusService.publish("modules.content.load",menu);
				}else {
					eventBusService.publish("modules.content.load",menu);
				}
			}
		}
		if(event=='delete'){
			var values = [];
			var ids="";
			$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
				var arr=$(this).val().split(',');
				values.push(arr[0]);
				ids = ids+",'"+arr[0]+"'";
			});
			if(values.length < 1){
				eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择修改数据。"});
			}else{
				eventBusService.publish("modal.alert",{"content":"你是否确认删除这"+values.length+"数据？","isAutoClose":false,"confirm":function(){
						// httpService.post(app.urls.user_delete,{"id":ids.replace(',','')},function(data){
						// 	if("0000" === data.code){
								httpService.post(app.urls.expert_delete,{"id":ids.replace(',','')}, function(data) {
									if ("0000" === data.code) {
										$scope.select();
									} else {
										alert(data.msg);
									}
								});
						// 	}else{
						// 		alert(data.msg);
						// 	}
						// });
					},"cancel":function(){
						//用户取消，不做操作
					}});
			}
		}
		if(event=='resetPwd'){
			var values = [];
			var ids="";
			$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
				var arr=$(this).val().split(',');
				values.push(arr[0]);
				ids = ids+","+arr[0]+"";
			});
			if(values.length < 1){
				eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择修改数据。"});
			}else{
				eventBusService.publish("modal.alert",{"content":"你是否重置这"+values.length+"名用户密码？","isAutoClose":false,"confirm":function(){
					
					httpService.post(app.urls.user_resetPwd,{"ids":ids.replace(',',''),"type":'5'}, function(data) {
						if ("0000" === data.code) {
							console.info(data.data=="");
							if(data.data==""){
								alert(data.msg);
							}else{
								alert(data.msg+"但其中["+data.data+"]密码重置失败!")
							}
						} else {
							alert(data.msg);
						}
					});
					
					},"cancel":function(){
						//用户取消，不做操作
					}});
			}
		}
	}
	//返回
	$scope.goback = function(){
		var menu = {"url": "modules/content/welcome/unit"};
		eventBusService.publish("modules.content.load", menu);
	}
	//接收数据刷新
	eventBusService.subscribe('content.page.reload', function(event,data) {
		$scope.select();
	});
	
	$scope.showul=function(num){
		$(".gzdw").removeClass("ss-display");
	}
	
	$scope.getSchool=function(school,num){
		if(school == 0){
			$scope.form.fk_unit = "";
			$scope.gzdwname = "";
			$(".gzdw").addClass("ss-display");
		}else{
			$scope.form.fk_unit = school.id;
			$scope.gzdwname = school.name;
			$(".gzdw").addClass("ss-display");
		}
	}
}}});